﻿using System;
using System.Linq;
using System.Web.Security;

//using System.Web.SessionState;
//using System.Security.Principal;

namespace Ones
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
        }

        protected void Session_Start(object sender, EventArgs e)
        {
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            FormsIdentity identity = null;
            string roles = null;

            if (Context.Request.IsAuthenticated)
            {
                if (Context.User.Identity.AuthenticationType == "Forms")
                {
                    identity = (FormsIdentity)(Context.User.Identity);
                    roles = identity.Ticket.UserData;

                    Context.User = new System.Security.Principal.GenericPrincipal(identity, roles.Split(','));
                }
                else
                {
                    throw new ApplicationException("Application Must Be Configured For Forms Authentication");
                }
            }
        }

        protected void Application_Error(object sender, EventArgs e)
        {
        }

        protected void Session_End(object sender, EventArgs e)
        {
        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}